<?php
/**
* 订单模块后台 Controller
*
* 订单模块后台 Controller的注意及说明
* 以下use模块请不要互相伤害
*
* @author    xiecz <xiecz@yunys.com.cn>
* @copyright 2016 QuanZhouYunYiShang Inc.
*/

namespace App\Http\Controllers\Backstage;

use Illuminate\Routing\Controller as BaseController;
use Response, Request;
use App\Services\Order\OrderBackstage;
use App\Services\Tool\ExpressTool;
use App\Services\Order\AfterBackstage;
use App\Services\ProductTempService\ProductTempTool;

class OrderController extends BaseController{

    function __construct(OrderBackstage $orderBackstage,
                         AfterBackstage $afterBackstage,
                         ProductTempTool $productTempTool){
        $this->back  = $orderBackstage;
        $this->after = $afterBackstage;
        $this->productTempTool = $productTempTool;
        $this->middleware('transaction',['only'=>['createOrder']]);
    }

    /**
     * 订单列表
     * @return mixed
     */
    function orderList(){
        $input  = Request::all();
        $result = $this->back->order_list($input);
        $express = ExpressTool::get_express_list();
        return view('backstage.order.order-list')->with('orders',$result)
                                                 ->with('express',$express);
    }

    /**
     * 订单详情
     * @return mixed
     */
    function orderDetail(){
        $input  = Request::all();
        $result = $this->back->order_detail($input);
        $express = ExpressTool::get_express_list();
        return view('backstage.order.order-detail')->with('order',$result)
                                                   ->with('express',$express);
    }

    /**
     * 确认订单
     */
    function orderConfirm(){
        $input  = Request::all();
        $result = $this->back->orderConfirm($input);
        return response()->json($result);
    }

    /**
     * 发货
     * @return mixed
     */
    function orderSend(){
        $input  = Request::all();
        $result = $this->back->order_send($input);
        return response()->json($result);
    }

    /**
     * 修改订单后备注
     * @return mixed
     */
    function updateOrderBackMessage(){
        $input  = Request::all();
        $result = $this->back->update_order_back_message($input);
        return response()->json($result);
    }

    /**
     * 修改订单收获信息
     * @return mixed
     */
    function updateOrderRece(){
        $input  = Request::all();
        $result = $this->back->update_order_rece($input);
        return response()->json($result);
    }

    /**
     * 订单打印图zip生成返链接
     * @return mixed
     */
    function createOrderZip(){
        $input  = Request::all();
        $result = $this->back->create_order_zip($input);
        return response()->json($result);
    }

    /**
     * 生产Excel
     * @return mixed
     */
    function createExcel(){
        $input  = Request::all();
        $result = $this->back->create_excel($input);
        return response()->json($result);
    }

    /**
     * 修改打印进度
     * @return mixed
     */
    function updateOrderPrintState(){
        $input  = Request::all();
        $result = $this->back->update_order_print_state($input);
        return response()->json($result);
    }

    /**
     *  关闭工单
     */
    function closeWorksheet(){
        $input  = Request::all();
        $result = $this->back->close_worksheet($input);
        return response()->json($result);
    }

    /**
     *  取消订单页面
     */
    function order_cancel_blade(){
        $input  = Request::all();
        $result = $this->back->order_cancel_blade($input);
        if($result['state'] == 'M00000')
            return view('backstage.order.order-cancel')->with('result',$result['result']);
        else
            return $result['message'];
    }

    /**
     * 取消订单
     */
    function order_cancel(){
        $input  = Request::all();
        $result = $this->back->order_cancel_from_backstage($input);
        return response()->json($result);
    }

    /**
     * 支付宝退款确认页
     */
    function show_alirefund(){
        $input  = Request::all();
        $result = $this->back->show_alirefund($input);
        if($result['state']=='M00000'){
            return view('backstage.order.alipay-refund')->with('result',$result['result']);
        }else{
            return $result['message'];
        }
    }

    /**
     * 支付宝退款页
     */
    function alirefund(){
        $input  = Request::all();
        return view('backstage.order.alipayapi')->with('result',$input);
    }

    /**
     * 手工单
     */

    /**
     * 添加手工单页面
     */
    function createOrderPage(){
        $temp = $this->productTempTool->getProductTempsByProductTempIds([]);
        return view('backstage.order.create-order')->with('temps',$temp);
    }

    /**
     * 添加手工单
     */
    function createOrder(){
        $input  = Request::all();
        $result = $this->back->create_order_by_backstage($input);
        return response()->json($result);
    }

    /**
     * 产品模版编号获取详情
     */
    function getProductInfo(){
        $input  = Request::all();
        $result = $this->back->get_product_info($input);
        return response()->json($result);
    }

    /**
     * 查询尺码
     */
    function findSize(){
        $input  = Request::all();
        $result  = $this->back->findSize($input);
        return response()->json($result);
    }

    /**
     * 订单统计
     */
    function order_statistics(){
        $input  = Request::all();
        $result = $this->back->order_statistics($input);
        return response()->json($result);
    }

    /**
     * 订单统计
     */
    function statistics(){
        return view('backstage.order.ECharts.test');
    }


    /**
     * 售后
     */

    /**
     * 售后列表
     */
    function aftermarkList(){
        $input  = Request::all();
        $result = $this->after->aftermark_list($input);
        return view('backstage.order.aftermark-list')->with('afters',$result);
    }

    /**
     * 售后详情
     */
    function aftermarkDetail(){
        $input  = Request::all();
        $result = $this->after->aftermark_detail($input);
        $express = ExpressTool::get_express_list();
        return view('backstage.order.aftermark-detail')->with('after',$result)
                                                       ->with('express',$express);
    }

    /**
     * 修改售后审核结果
     */
    function updateAfterState(){
        $input  = Request::all();
        $result = $this->after->update_after_state($input);
        return response()->json($result);
    }

    /**
     * 修改售后结果描述
     */
    function updateResultDesc(){
        $input  = Request::all();
        $result = $this->after->update_result_desc($input);
        return response()->json($result);
    }

    /**
     * 重新寄出
     */
    function systemResendExpress(){
        $input  = Request::all();
        $result = $this->after->system_resend_express($input);
        return response()->json($result);
    }

    /**
        修改售后单备注信息
     */
    function updateAftermarkBackRemark(){
        $input  = Request::all();
        $result = $this->after->update_aftermark_back_remark($input);
        return response()->json($result);
    }

    /**
        打包售后单打印图
     */
    function createAfterZip(){
        $input  = Request::all();
        $result = $this->after->create_after_zip($input);
        return response()->json($result);
    }


    /**
     *
     */
    function test(){
        return view('backstage.order.ECharts.test');
    }
}
